export default {
  namespaced: true,
  state: {
    contacts: [
      {
        id: 1,
        name: '小霞',
        tel: 109874839454,
        address: '安徽省合肥市瑶海区XXX小区',
        province: '安徽省',
        city: '合肥市',
        county: '瑶海区',
        addressDetail: '安徽省合肥市瑶海区XXX小区',
        areaCode: 334545,
        isDefault: true
      },
      {
        id: 2,
        name: '小宇',
        tel: 109874839454,
        address: '安徽省合肥市瑶海区XXX小区',
        province: '安徽省',
        city: '合肥市',
        county: '瑶海区',
        addressDetail: '安徽省合肥市瑶海区XXX小区',
        areaCode: 334545,
        isDefault: false
      },
      {
        id: 3,
        name: '小张',
        tel: 109874832354,
        address: '安徽省合肥市瑶海区XXX小区',
        province: '安徽省',
        city: '合肥市',
        county: '瑶海区',
        addressDetail: '安徽省合肥市瑶海区XXX小区',
        areaCode: 334545,
        isDefault: false
      }
    ]
  },
  mutations: {
    add_contact (state, contact) {
      if (contact.isDefault) {
        const index = state.contacts.findIndex(el => el.isDefault)
        if (index === -1) {
          state.contacts.push(contact)
        } else {
          state.contacts[index].isDefault = false
          state.contacts.push(contact)
        }
      }
    }
  }
}
